package com.lp.mgt.commons;

import com.lp.mgt.constants.ExceptionEnums;

/**
 * @program: 测试
 * @description:返回的JSON数据结构标准
 * @author: 
 * @create: 2018-10-17 09:01
 **/
public class CustomResult <T>{
	private boolean success;
	private String status;
	private T data;
	private String errCode;
	private String errMsg;
 
	public CustomResult(){}
 
	public CustomResult(boolean success, T data) {
		super();
		this.success = success;
		this.data = data;
	}
 
	@Override
	public String toString() {
		return "ResponseBean{" +
				"success=" + success +
				", data=" + data +
				", errCode='" + errCode + '\'' +
				", errMsg='" + errMsg + '\'' +
				'}';
	}
 
	public CustomResult(boolean success, T data, String errCode, String errMsg) {
		super();
		this.success = success;
		this.data = data;
		this.errCode = errCode;
		this.errMsg = errMsg;
	}
	
	public CustomResult(String status, T data, String errCode, String errMsg) {
		super();
		this.status = status;
		this.data = data;
		this.errCode = errCode;
		this.errMsg = errMsg;
	}
 
	public CustomResult(boolean success, String errCode, String errMsg) {
		this.success = success;
		this.errCode = errCode;
		this.errMsg = errMsg;
	}
	public CustomResult(boolean success,ExceptionEnums enums){
		this.success=success;
		this.errCode=enums.getCode();
		this.errMsg=enums.getMsg();
	}
	public CustomResult(boolean success,T data,ExceptionEnums enums){
		this.success=success;
		this.data=data;
		this.errCode=enums.getCode();
		this.errMsg=enums.getMsg();
	}
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	public String getErrCode() {
		return errCode;
	}
	public void setErrCode(String errCode) {
		this.errCode = errCode;
	}
	public String getErrMsg() {
		return errMsg;
	}
	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}
	
	public CustomResult failure(Boolean isSuccess,String errCode,String errMsg) {
		this.success=isSuccess;
		this.errCode=errCode;
		this.errMsg=errMsg;
		return this;
	}
	
	public CustomResult success(Boolean isSuccess,T data) {
		this.success=isSuccess;
		this.data=data;
		return this;
	}
	
	public CustomResult success(Boolean isSuccess,String errCode,String errMsg) {
		this.success=isSuccess;
		this.errCode=errCode;
		this.errMsg= errMsg;
		return this;
	}
	
	public CustomResult success(Boolean isSuccess,String errMsg) {
		this.success=isSuccess;
		this.errMsg= errMsg;
		return this;
	}
	public CustomResult success(Boolean isSuccess) {
		this.success=isSuccess;
		return this;
	}
}